home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1993 July / InfoMagic USENET CD-ROM July 1993.ISO / sources / misc / volume10 / a2ps3 < prev    next >
Encoding:
Text File  |  1990-02-16  |  38.3 KB  |  1,393 lines

  1. Newsgroups: comp.sources.misc
  2. organization: IMAG, University of Grenoble, France
  3. subject: v10i073: A2ps v3.0
  4. from: miguel@imag.imag.fr (Miguel Santana)
  5. Sender: allbery@uunet.UU.NET (Brandon S. Allbery - comp.sources.misc)
  6.  
  7. Posting-number: Volume 10, Issue 73
  8. Submitted-by: miguel@imag.imag.fr (Miguel Santana)
  9. Archive-name: a2ps3
  10.  
  11. This is version 3.0 of a2ps, a program to format an ascii file for
  12. printing in a postcript printer. The format used is nice and compact:
  13. normally two pages on each physical page, borders surrounding pages,
  14. headers with useful information (page number, printing date, file name),
  15. line numbering, etc. Very useful to archive listings of programs.
  16.  
  17. A2ps offers many options: multiple copies, landscape and portrait mode,
  18. wide format, lines numbering, fold/cut lines too large, font size, etc.
  19. User could adapt the printing format to his own preferences with these
  20. options.
  21.  
  22. Please, follow the instructions in README file to install a2ps in your
  23. computer. Use sh to unpacking.
  24.  
  25.     Miguel SANTANA
  26.  
  27. ----------------------- cut here -----------------------
  28. #! /bin/sh
  29. # This is a shell archive.  Remove anything before this line, then unpack
  30. # it by saving it into a file and typing "sh file".  To overwrite existing
  31. # files, type "sh file -c".  You can also feed this as standard input via
  32. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  33. # will see the following message at the end:
  34. #        "End of shell archive."
  35. # Contents:  README Makefile a2ps.1 a2ps.c header.ps
  36. # Wrapped by miguel@bounty on Wed Jan 10 15:37:53 1990
  37. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  38. if test -f 'README' -a "${1}" != "-c" ; then 
  39.   echo shar: Will not clobber existing file \"'README'\"
  40. else
  41. echo shar: Extracting \"'README'\" \(2116 characters\)
  42. sed "s/^X//" >'README' <<'END_OF_FILE'
  43. XThis is version 3.0 of a2ps, a program to format an ascii file for
  44. Xprinting in a postcript printer. As the copyright indicates, this
  45. Xdistribution can be freely redistributed.
  46. X
  47. XInitial version was a shell program written by evan@csli (Evan
  48. XKirshenbaum). It was very slow and contained many bugs. A new
  49. Xversion was written in C for improve speed execution and portability.
  50. XMany new features and improvements have been added.
  51. X
  52. X
  53. XSome notes on the distribution:
  54. X
  55. X    Installation is done by modifying and executing Makefile included
  56. X    in this distribution. You must give a value to two variables:
  57. X    - HEADER_PS    a2ps will search there the file header.ps at execution
  58. X        time.
  59. X    - compiler    compiler name, actually one of BSD, SYSV, ANSIC. Turbo
  60. X        C and Microsoft C are considered ANSIC compilers.
  61. X    You could also give your own values to following variables:
  62. X    a) Physical page dimension. Dimensions must be real constants,
  63. X       specifying inch values.
  64. X       - HEIGHT     sheet height
  65. X       - WIDTH     sheet width
  66. X       Default values correspond to A4 format (11.64 x 8.27). In USA, you use
  67. X       use in general 11.0 x 8.5.
  68. X    b) Total lateral (left+right) or vertical (top+bottom) margins. It must
  69. X       be also a real constant, specifying inchs (by default 1.2).
  70. X       - MARGIN
  71. X    c) Directory separator (by default '/')
  72. X       - DIR_SEP char
  73. X
  74. X    a2ps has been successfully ported to Unix 4.3BSD, Unix SystemV and
  75. X    MSDOS.
  76. X
  77. X
  78. XThe a2ps distribution consists of the following files:
  79. X
  80. X    README        This message
  81. X    Makefile
  82. X    a2ps.c        a2ps source
  83. X    a2ps.1        a troff manual (man file)
  84. X    header.ps    postcript header used by a2ps
  85. X
  86. XDecide where you want to keep these files and move it there.
  87. XEdit "Makefile" and change the definition of HEADER_PS (to
  88. Xreflect the full pathname of header.ps) and of compiler name.
  89. XTo make a2ps do:
  90. X
  91. X    make a2ps
  92. X
  93. XTo install it, do:
  94. X
  95. X    make install
  96. X
  97. XFormat the manual entry using
  98. X
  99. X    nroff -man a2ps.1
  100. X
  101. X
  102. XPlease send problems and feedback to:
  103. X
  104. X    miguel@imag.fr or miguel@imag.UUCP (uunet.uu.net!imag!miguel)
  105. X
  106. X    Miguel SANTANA
  107. X    LGI
  108. X    IMAG-Campus
  109. X    BP 53X
  110. X    38041 Grenoble Cedex
  111. END_OF_FILE
  112. if test 2116 -ne `wc -c <'README'`; then
  113.     echo shar: \"'README'\" unpacked with wrong size!
  114. fi
  115. chmod +x 'README'
  116. # end of 'README'
  117. fi
  118. if test -f 'Makefile' -a "${1}" != "-c" ; then 
  119.   echo shar: Will not clobber existing file \"'Makefile'\"
  120. else
  121. echo shar: Extracting \"'Makefile'\" \(1325 characters\)
  122. sed "s/^X//" >'Makefile' <<'END_OF_FILE'
  123. X#
  124. X# Description: Makefile to construct and install a2ps. Don't forget
  125. X# to give your own values to define variables HEADER_PS and name of
  126. X# compiler (see OPTIONS).
  127. X#
  128. X# File: imag:/users/local/a2ps/Makefile
  129. X# Created: Mon Nov 29 14:05:39 1988 by miguel@imag (Miguel Santana)
  130. X# Version: 2.0
  131. X#
  132. X
  133. X# Copyright (c) 1988, Miguel Santana, miguel@imag.imag.fr
  134. X#
  135. X# Permission is granted to copy and distribute this file in modified
  136. X# or unmodified form, whether for noncommercial or commercial use,
  137. X# provided (a) this copyright notice is preserved, (b) no attempt is
  138. X# made to restrict redistribution of this file, and (c) this file is
  139. X# not distributed as part of any collection whose redistribution is
  140. X# restricted by a compilation copyright.
  141. X#
  142. X
  143. XD    =.
  144. X
  145. XO    =.
  146. X
  147. XI    =/usr/local/bin
  148. X
  149. XL    =/usr/local/lib
  150. X
  151. XHEADER    =a2ps.header.ps
  152. X
  153. XOPTIONS    =-DHEADER_PS="\"$L/$(HEADER)\"" -DBSD -O
  154. X# Default values for HEIGHT, WIDTH, MARGIN and DIR_SEP (11.64, 8.27, 1.2, /).
  155. X
  156. XOBJS          = a2ps.o
  157. X
  158. Xa2ps:        a2ps.o
  159. X        @echo -n "Compiling and linking a2ps ... "
  160. X        @cc -o $D/xa2ps a2ps.o
  161. X        @echo "done"
  162. X
  163. Xall:        a2ps install
  164. X
  165. Xinstall:;    @echo -n "Installing a2ps ... "
  166. X        @cp xa2ps $I/a2ps
  167. X        @cp header.ps $L/$(HEADER)
  168. X        @echo "done"
  169. X
  170. Xshar:;        @shar -b -oa2ps.shar README Makefile a2ps.1 a2ps.c header.ps
  171. X
  172. Xclean:;        @rm -f $(OBJS) xa2ps
  173. X
  174. Xa2ps.o:;
  175. X        cc -c $(OPTIONS) a2ps.c
  176. X
  177. END_OF_FILE
  178. if test 1325 -ne `wc -c <'Makefile'`; then
  179.     echo shar: \"'Makefile'\" unpacked with wrong size!
  180. fi
  181. # end of 'Makefile'
  182. fi
  183. if test -f 'a2ps.1' -a "${1}" != "-c" ; then 
  184.   echo shar: Will not clobber existing file \"'a2ps.1'\"
  185. else
  186. echo shar: Extracting \"'a2ps.1'\" \(4522 characters\)
  187. sed "s/^X//" >'a2ps.1' <<'END_OF_FILE'
  188. X.\" @(#)a2ps.man.1 2.0 11/29/88
  189. X.\"
  190. X.TH A2PS 1L "24 July 1989"
  191. X.UC 4
  192. X.SH NAME
  193. Xa2ps \- formats an ascii file for printing on a postscript printer
  194. X.SH SYNOPSIS
  195. X.B a2ps
  196. X[
  197. X.B -#num
  198. X] [
  199. X[
  200. X.B -?
  201. X] [
  202. X.B -b
  203. X] [
  204. X.B -f
  205. X] [
  206. X.B -fnum
  207. X] [
  208. X[
  209. X.B -h
  210. X] [
  211. X.B -i
  212. X] [
  213. X.B -n
  214. X] [ \fB-n\fP{\fBbfhinprsvw\fP} ] [
  215. X.B -p
  216. X] [
  217. X.B -r
  218. X] [
  219. X.B -tnum
  220. X] [
  221. X.B -v
  222. X] [
  223. X.B -w
  224. X] [
  225. X.I file
  226. X] ...
  227. X.SH DESCRIPTION
  228. X.I a2ps
  229. Xformats each named file for printing in a postscript printer;
  230. Xif no file is given,
  231. X.I a2ps
  232. Xreads from the standard input.
  233. XThe format used is nice and compact: normally
  234. Xtwo pages on each physical page,
  235. Xborders surrounding pages, headers with useful information (page number,
  236. Xprinting date, file name), line numbering, etc. Very useful to
  237. Xarchive listings of programs.
  238. X.PP
  239. XOptions offered by
  240. X.I a2ps
  241. Xare the following:
  242. X.TP 0.6i
  243. X.B -#num
  244. XTo get multiple copies of output, where
  245. X.I num
  246. Xis the number of copies desired of each file named. By default, you get
  247. Xonly one copy.
  248. X.TP 0.6i
  249. X.B -?
  250. XPrint usage information.
  251. X.TP 0.6i
  252. X.B -b
  253. XForce printing binary files. By default, binary files printing is
  254. Xstopped before second page (see -nb option).
  255. X.TP 0.6i
  256. X.B -f
  257. XFold lines too large to be printed inside the borders (default option).
  258. XMax size depends on format and font size used.
  259. X.TP 0.6i
  260. X.B -fnum
  261. XChanges font size to this value. Default values for font size are 6.8 in
  262. Xlandscape mode and 9.0 in portrait mode. Try other sizes if you think that
  263. Xthese values are too small (or big).
  264. X.TP 0.6i
  265. X.B -h
  266. XPrint usage information.
  267. X.TP 0.6i
  268. X.B -i
  269. XInterpret TAB, BS and FF characters (default option). TAB is replaced by
  270. Xenough spaces to reach next tab stop while BS and FF have their meanings.
  271. X.TP 0.6i
  272. X.B -n
  273. XOutput lines are preceded by line numbers, numbered sequentially from 1
  274. X(default option).
  275. X.TP 0.6i
  276. X.B -nb
  277. XDon't print binary files. To detect such a file we make use of a
  278. Xvery simple heuristic: if the first page of the file contains at
  279. Xless 75% of non-printing characters, it's a binary file. First page
  280. Xis always printed.
  281. X.TP 0.6i
  282. X.B -nf
  283. XCut lines too large (don't fold).
  284. X.TP 0.6i
  285. X.B -nh
  286. XDon't print page headers.
  287. X.TP 0.6i
  288. X.B -ni
  289. XDon't interpret TAB, BS and FF characters. They will be printed
  290. Xaccording to -v option.
  291. X.TP 0.6i
  292. X.B -nn
  293. XDon't number output lines.
  294. X.TP 0.6i
  295. X.B -np
  296. XDon't print pages in portrait mode (see -p option) but in landscape mode.
  297. X.TP 0.6i
  298. X.B -nr
  299. XSheet numbering (see -r option) must be continue for all files (don't
  300. Xreset on new file).
  301. X.TP 0.6i
  302. X.B -ns
  303. XDon't print page surrounding borders.
  304. X.TP 0.6i
  305. X.B -nv
  306. XReplace non-printing characters by a space.
  307. X.TP 0.6i
  308. X.B -nw
  309. XDon't use wide format (see -w option).
  310. X.TP 0.6i
  311. X.B -p
  312. XPrint files in portrait mode, one page per physical sheet.
  313. XThe default option is to use landscape mode and print two pages on a physical
  314. Xsheet. This option may not be used with the -w option.
  315. X.TP 0.6i
  316. X.B -r
  317. XReset sheet numbering for each new file (default option). Sheet numbering
  318. Xis used to number physical pages (sheets printed) and is placed
  319. Xin the bottom of each physical page. It differs from page numbering: logical
  320. Xpages of file been printed.
  321. X.TP 0.6i
  322. X.B -tnum
  323. XSet TAB size to \fInum\fR (default 8).
  324. XThis option is ignored if \fB-ni\fR is specified (see below).
  325. X.TP 0.6i
  326. X.B -v
  327. XReplace non-printing characters so that they are visible and easy to identify
  328. X(default option). Control characters (ascii codes lower than 0x20) are
  329. Xprinted like ^X for ctrl-x; the delete character (hex 0x3f) is printed
  330. Xas ^?. Non ascii characters (with the high bit set) are printed as M-
  331. X(for meta) followed by the character of the low 7 bits. TAB, BS and FF are
  332. Xhandled like non-printing characters if -ni option was taked.
  333. X+ .TP 0.6i
  334. X.B -w
  335. XUse wide format pages. This will result in only one page per physical sheet
  336. Xbut in landscape mode. This option may not be used with the -p option.
  337. X.SH USAGE
  338. X.PP
  339. X.I A2ps
  340. Xsends formatted file to standard output. The user could redirect this output
  341. Xto a file, pipe it directly to a print command (like lpr), or pipe it to
  342. Xanother filter for further processing.
  343. X
  344. X.ti +0.5i
  345. Xa2ps file1 > file2
  346. X
  347. X.ti +0.5i
  348. Xa2ps file1 | lpr -l -Pps
  349. X
  350. X.ti +0.5i
  351. Xa2ps -p file1 | psnup -n4 | lpr -l -Pps
  352. X.PP
  353. XDon't forget
  354. X.B -l
  355. Xoption in
  356. X.I lpr
  357. X, if you want that 
  358. X.I lpr
  359. Xinterprets your postscript program.
  360. X.PP
  361. XThis filter must be used only with text files. Avoid specially output from
  362. XTeX, troff or any other such text formatters.
  363. X.SH "SEE ALSO"
  364. Xtgrind(1) lpr(1) pprps(1L)
  365. X.SH AUTHORS
  366. XEvan Kirshenbaum (evan@csli) for the initial version.
  367. X.br
  368. XMiguel Santana (miguel@imag.imag.fr) for versions 1.0, 2.0 et 3.0.
  369. X
  370. END_OF_FILE
  371. if test 4522 -ne `wc -c <'a2ps.1'`; then
  372.     echo shar: \"'a2ps.1'\" unpacked with wrong size!
  373. fi
  374. # end of 'a2ps.1'
  375. fi
  376. if test -f 'a2ps.c' -a "${1}" != "-c" ; then 
  377.   echo shar: Will not clobber existing file \"'a2ps.c'\"
  378. else
  379. echo shar: Extracting \"'a2ps.c'\" \(18394 characters\)
  380. sed "s/^X//" >'a2ps.c' <<'END_OF_FILE'
  381. X/************************************************************************/
  382. X/*                                    */
  383. X/* Description: Ascii to PostScript printer program.            */
  384. X/* File: imag:/users/local/a2ps/a2ps.c                    */
  385. X/* Created: Mon Nov 28 15:22:15 1988 by miguel@imag (Miguel Santana)    */
  386. X/* Version: 2.0                                */
  387. X/*                                    */
  388. X/* Edit history:                            */
  389. X/* 1) Derived of shell program written by evan@csli (Evan Kirshenbaum).    */
  390. X/*    Written in C for improve speed execution and portability. Many    */
  391. X/*    improvements have been added.                    */
  392. X/* Fixes by Oscar Nierstrasz @ cui.uucp:                */
  393. X/* 2) Fixed incorrect handling of stdin (removed error if no file names)*/
  394. X/* 3) Added start_page variable to eliminate blank pages printed for    */
  395. X/*    files that are exactly multiples of 132 lines (e.g., man pages)    */
  396. X/* Modified by miguel@imag:                        */
  397. X/* 4) Added new options at installation : sheet format (height/width in    */
  398. X/*    inches), page format (number of columns per line and of lines per    */
  399. X/*    page).                                */
  400. X/* Modified by miguel@imag:                        */
  401. X/* 5) Added new option to print n copies of a same document.        */
  402. X/* 6) Cut long filenames if don't fit in the page header.        */
  403. X/* Modified by Tim Clark (T.Clark@warwick.ac.uk):            */
  404. X/* 7) Two additional modes of printing (portrait and wide format modes)    */
  405. X/* 8) Fixed to cope with filenames which contain a character which must    */
  406. X/*    be escaped in a PostScript string.                */
  407. X/* Modified by miguel@imag.fr to                    */
  408. X/* 9) Add new option to suppress heading printing.            */
  409. X/* 10) Add new option to suppress page surrounding border printing.    */
  410. X/* 11) Add new option to change font size. Number of lines and columns    */
  411. X/*     are now automatically adjusted, depending on font size and    */
  412. X/*     printing mode used.                        */
  413. X/* 12) Minor changes (best layout, usage message, etc).            */
  414. X/*                                    */
  415. X/************************************************************************/
  416. X
  417. X/*
  418. X * Copyright (c) 1988, Miguel Santana, miguel@imag.imag.fr
  419. X *
  420. X * Permission is granted to copy and distribute this file in modified
  421. X * or unmodified form, for noncommercial use, provided (a) this copyright
  422. X * notice is preserved, (b) no attempt is made to restrict redistribution
  423. X * of this file, and (c) this file is not distributed as part of any
  424. X * collection whose redistribution is restricted by a compilation copyright.
  425. X*/
  426. X
  427. X
  428. X#include <stdio.h>
  429. X#include <ctype.h>
  430. X#ifdef ANSIC
  431. X#include <sys/types.h>
  432. X#include <time.h>
  433. X#else
  434. X#ifdef BSD
  435. X#include <sys/time.h>
  436. X#else
  437. X#ifdef SYSV
  438. X#include <sys/types.h>
  439. X#include <sys/timeb.h>
  440. X#include <time.h>
  441. X#else
  442. Xerror !
  443. X#endif
  444. X#endif
  445. X#endif
  446. X
  447. X#ifndef    HEADER_PS
  448. X#define    HEADER_PS    "./header.ps"
  449. X#endif
  450. X
  451. X#ifndef WIDTH
  452. X#define    WIDTH    8.27
  453. X#endif
  454. X
  455. X#ifndef HEIGHT
  456. X#define    HEIGHT    11.64
  457. X#endif
  458. X
  459. X#ifndef MARGIN
  460. X#define    MARGIN    1.2
  461. X#endif
  462. X
  463. X#ifndef DIR_SEP
  464. X#define    DIR_SEP    '/'
  465. X#endif
  466. X
  467. X#define    PORTRAIT_HEADER        0.29
  468. X#define    LANDSCAPE_HEADER    0.22
  469. X#define    PIXELS_INCH        72
  470. X#define MAXFILENAME        20
  471. X#define    FALSE            0
  472. X#define    TRUE            1
  473. X
  474. Xint fold_line();
  475. Xvoid print_file();
  476. Xchar cut_line();
  477. Xint printchar();
  478. Xvoid skip_page();
  479. X
  480. X
  481. Xint column = 0;            /* Column number (in current line) */
  482. Xint line = 0;            /* Line number (in current page) */
  483. Xint line_number = 0;        /* Source line number */
  484. Xint first_page;            /* First page for a file */
  485. Xint nonprinting_chars, chars;    /* Number of nonprinting and total chars */
  486. Xint prefix_width;        /* Width in characters for line prefix */
  487. Xint pages = 0;            /* Number of logical pages printed */
  488. Xint sheets = 0;            /* Number of physical pages printed */
  489. Xint linesperpage;        /* Lines per page */
  490. Xint columnsperline;        /* Characters per output line */
  491. X
  492. Xdouble font_size = 0.0;        /* Size of a char for body font */
  493. Xint numbering = TRUE;        /* Line numbering option */
  494. Xint folding = TRUE;        /* Line folding option */
  495. Xint restart = TRUE;        /* Restart page number at each file option */
  496. Xint only_printable = FALSE;    /* Replace non printable char by space option */
  497. Xint interpret = TRUE;        /* Interpret TAB, FF and BS chars option */
  498. Xint print_binaries = FALSE;    /* Force printing for binary files */ 
  499. Xint copies_number = 1;        /* Number of copies to print */
  500. Xint landscape = TRUE;        /* Otherwise portrait format sheets */
  501. Xint wide_pages = FALSE;         /* TRUE implies landscape, not twinpage */
  502. Xint twinpage = TRUE;        /* 2 pages per sheet if true, 1 otherwise */
  503. Xint no_border = FALSE;        /* TRUE if user don't want the border */
  504. Xint no_header = FALSE;        /* TRUE if user don't want the header */
  505. Xint column_width = 8;            /* default column tab width (8) */
  506. X
  507. Xmain(argc, argv)
  508. Xint argc;
  509. Xchar *argv[];
  510. X{
  511. X   register int narg;
  512. X   register char *arg;
  513. X   double char_width, header_size;
  514. X   double page_height, page_width;
  515. X   int i;
  516. X   extern double atof();
  517. X
  518. X   /* Option processing */
  519. X   arg = argv[narg = 1];
  520. X   while (narg < argc && arg[0] == '-')
  521. X   {
  522. X      switch (arg[1])
  523. X      {
  524. X      case '?':                    /* help */
  525. X     goto usage;
  526. X      case '#':                    /* n copies */
  527. X     copies_number = 0;
  528. X     arg += 2;
  529. X     while (*arg != NULL && isdigit(*arg))
  530. X        copies_number = copies_number*10 + (*arg++ - '0');
  531. X     if (*arg != NULL || copies_number <= 0)
  532. X        goto usage;
  533. X     break;
  534. X      case 'b':                    /* print binary files */
  535. X     if (arg[2] != NULL)
  536. X        goto usage;
  537. X     print_binaries = TRUE;
  538. X     break;
  539. X      case 'f':                    /* change font size */
  540. X     if (arg[2] == NULL) {
  541. X        folding = TRUE;
  542. X        break;
  543. X     }
  544. X     if ((font_size = atof(&arg[2])) == 0.0) {
  545. X        fprintf(stderr, "Wrong value for option -s\n");
  546. X        exit(1);
  547. X     }
  548. X     break;
  549. X      case 'h':                    /* help */
  550. X     goto usage;
  551. X      case 'i':                    /* interpret control chars */
  552. X     if (arg[2] != NULL)
  553. X        goto usage;
  554. X     interpret = TRUE;
  555. X     break;
  556. X      case 'n':                    /* number file lines */
  557. X     if (arg[2] == NULL)
  558. X     {
  559. X        numbering = TRUE;
  560. X        break;
  561. X     }
  562. X     if (arg[3] != NULL)
  563. X        goto usage;
  564. X     switch (arg[2])
  565. X     {
  566. X     case 'b':                /* don't print binaries */
  567. X        print_binaries = FALSE;
  568. X        break;
  569. X     case 'f':                /* cut lines too long */
  570. X        folding = FALSE;
  571. X        break;
  572. X     case 'h':                /* don't print header */
  573. X        no_header = TRUE;
  574. X        break;
  575. X     case 'i':                /* don't interpret ctrl chars */
  576. X        interpret = FALSE;
  577. X        break;
  578. X     case 'n':                /* don't number lines */
  579. X        numbering = FALSE;
  580. X        break;
  581. X     case 'p':                /* landscape format */
  582. X        landscape = TRUE;
  583. X        break;
  584. X     case 'r':                /* don't restart sheet number */
  585. X        restart = FALSE;
  586. X        break;
  587. X     case 's':                /* no surrounding border */
  588. X        no_border = TRUE;
  589. X        break;
  590. X     case 'v':                /* only printable chars */
  591. X        only_printable = TRUE;
  592. X        break;
  593. X     case 'w':                /* twin pages */
  594. X        wide_pages = FALSE;
  595. X        break;
  596. X     default:
  597. X        goto usage;
  598. X     }
  599. X     break;
  600. X      case 'p':                    /* portrait format */
  601. X     if (arg[2] != NULL)
  602. X        goto usage;
  603. X     if (wide_pages) {
  604. X        fprintf(stderr, "a2ps: options -p and -w are incompatible\n");
  605. X        exit(1);
  606. X     }
  607. X     landscape = FALSE;
  608. X     break;
  609. X      case 'r':                    /* restart sheet number */
  610. X     if (arg[2] != NULL)
  611. X        goto usage;
  612. X     restart = TRUE;
  613. X     break;
  614. X      case 't':                    /* set tab size */
  615. X     if (arg[2] == NULL || (column_width = atoi(arg+2)) <= 0)
  616. X        goto usage;
  617. X     break;
  618. X      case 'v':                    /* print control chars */
  619. X     if (arg[2] != NULL)
  620. X        goto usage;
  621. X     only_printable = FALSE;
  622. X     break;
  623. X      case 'w':                    /* wide format */
  624. X     if (arg[2] != NULL)
  625. X        goto usage;
  626. X     if (!landscape) {
  627. X        fprintf(stderr, "a2ps: options -p and -w are incompatible\n");
  628. X        exit(1);
  629. X     }
  630. X     wide_pages = TRUE;
  631. X     break;
  632. X      default:
  633. X      usage:
  634. X     fprintf(stderr,"Usage: %s [options] [f1 f2 ... fn]\n", argv[0]);
  635. X     fprintf(stderr,"options = -#num\t(number of copies to print)\n");
  636. X     fprintf(stderr,"          -?\t(print this information)\n");
  637. X     fprintf(stderr,"          -f\t(fold lines too large)\n");
  638. X     fprintf(stderr,"          -fnum\t(font size, num is a float number)\n");
  639. X     fprintf(stderr,"          -h\t(print this information)\n");
  640. X     fprintf(stderr,"          -i\t(interpret tab, bs and ff chars)\n");
  641. X     fprintf(stderr,"          -n\t(number line files)\n");
  642. X     fprintf(stderr,"          -p\t(print in portrait mode)\n");
  643. X     fprintf(stderr,"          -r\t(restart page number after each file)\n");
  644. X     fprintf(stderr,"          -tn\t(set tab size to n)\n");
  645. X     fprintf(stderr,"          -v\t(show non-printing chars in a clear form)\n");
  646. X     fprintf(stderr,"          -w\t(print in wide format)\n");
  647. X     fprintf(stderr,"          -nb\t(don't force printing binary files)\n");
  648. X     fprintf(stderr,"          -nf\t(don't fold lines)\n");
  649. X     fprintf(stderr,"          -nh\t(don't print the header)\n");
  650. X     fprintf(stderr,"          -ni\t(don't interpret special chars)\n");
  651. X     fprintf(stderr,"          -nn\t(don't number output lines)\n");
  652. X     fprintf(stderr,"          -np\t(don't print in portrait format)\n");
  653. X     fprintf(stderr,"          -nr\t(don't restart page number)\n");
  654. X     fprintf(stderr,"          -ns\t(don't print surrounding borders)\n");
  655. X     fprintf(stderr,"          -nv\t(replace non-printing chars by space)\n");
  656. X     fprintf(stderr,"          -nw\t(don't print in wide format)\n");
  657. X     exit(1);
  658. X      }
  659. X      arg = argv[++narg];
  660. X   }
  661. X   if (arg != NULL && strcmp(arg, "?") == 0)
  662. X      goto usage;
  663. X
  664. X   twinpage = landscape && !wide_pages;
  665. X   if (font_size == 0.0)
  666. X      font_size = landscape ? 6.8 : 9.0;
  667. X   page_height = (HEIGHT - MARGIN) * PIXELS_INCH;
  668. X   page_width = (WIDTH - MARGIN) * PIXELS_INCH;
  669. X   char_width = 0.6 * font_size;
  670. X   if (landscape) {
  671. X      header_size = no_header ? 0.0 : LANDSCAPE_HEADER * PIXELS_INCH;
  672. X      linesperpage = ((page_width - header_size) / font_size) - 1;
  673. X      if (wide_pages)
  674. X     columnsperline = (page_height / char_width) - 1;
  675. X      else
  676. X     columnsperline = ((page_height / 2) / char_width) - 1;
  677. X   }
  678. X   else {
  679. X      header_size = no_header ? 0.0 : PORTRAIT_HEADER * PIXELS_INCH;
  680. X      linesperpage = ((page_height - header_size) / font_size) - 1;
  681. X      columnsperline = (page_width / char_width) - 1;
  682. X   }
  683. X   if (linesperpage <= 0 || columnsperline <= 0) {
  684. X      fprintf(stderr, "Font %g too big !!\n", font_size);
  685. X      exit(1);
  686. X   }
  687. X
  688. X   /* Header printing (postcript prolog) */
  689. X   print_header();
  690. X
  691. X   /* Print files designated or standard input */
  692. X   prefix_width = numbering ? 6 : 1;
  693. X   if (narg >= argc)
  694. X      print_file("stdin");
  695. X   else
  696. X   {
  697. X      while (narg < argc)
  698. X      {
  699. X     if (freopen(arg, "r", stdin) == NULL)
  700. X     {
  701. X        fprintf(stderr, "Error opening %s\n", arg);
  702. X        printf("\n%%%%Trailer\ncleanup\ndocsave restore end\n");
  703. X        exit(1);
  704. X     }
  705. X     print_file(arg);
  706. X     arg = argv[++narg];
  707. X      }
  708. X   }
  709. X
  710. X   printf("\n%%%%Trailer\ncleanup\ndocsave restore end\n");
  711. X}
  712. X
  713. Xvoid print_file(name)
  714. Xchar *name;
  715. X{
  716. X   register int c;
  717. X   int start_line, continue_exit;
  718. X   int char_width;
  719. X   int start_page;
  720. X   char new_name[MAXFILENAME+1];
  721. X   char *p;
  722. X
  723. X   /*
  724. X    * Boolean to indicates that previous char is \n (or interpreted \f)
  725. X    * and a new page would be started, if more text follows
  726. X    */
  727. X   start_page = FALSE;
  728. X
  729. X   /*
  730. X    * Printing binary files is not very useful. We stop printing
  731. X    * if we detect one of these files. Our heuristic to detect them:
  732. X    * if 50% characters of first page are non-printing characters,
  733. X    * the file is a binary file.
  734. X    * Option -b force binary files impression.
  735. X    */
  736. X   first_page = TRUE;
  737. X   nonprinting_chars = chars = 0;
  738. X
  739. X   /*
  740. X    * Preprocessing (before printing):
  741. X    * - TABs expansion (see interpret option)
  742. X    * - FF and BS interpretation
  743. X    * - replace non printable characters by a space or a char sequence
  744. X    *   like:
  745. X    *     ^X for ascii codes < 0x20 (X = [@, A, B, ...])
  746. X    *     ^? for del char
  747. X    *     M-c for ascii codes > 0x3f
  748. X    * - prefix parents and backslash ['(', ')', '\'] by backslash
  749. X    *   (escape character in postcript)
  750. X    */
  751. X   column = 0;
  752. X   line = line_number = 0;
  753. X   start_line = TRUE;
  754. X
  755. X   if (strlen(name) > MAXFILENAME) {
  756. X      cut_filename(name, new_name);
  757. X      name = new_name;
  758. X   }
  759. X   putchar('(');
  760. X   for (p = name; *p != NULL;)
  761. X      printchar(*p++);
  762. X   printf(") newfile\n");
  763. X
  764. X   if (restart)
  765. X      printf("/sheet 1 def\n");
  766. X
  767. X   pages = 0;
  768. X   skip_page();
  769. X
  770. X   c = getchar();
  771. X   while (c != EOF)
  772. X   {
  773. X      /* Form feed */
  774. X      if (c == '\f' && interpret)
  775. X      {
  776. X     /* Close current line */
  777. X     if (!start_line)
  778. X     {
  779. X        printf(") s\n");
  780. X        start_line = TRUE;
  781. X     }
  782. X     /* start a new page ? */
  783. X     if (start_page)
  784. X        skip_page();
  785. X     /* Close current page and begin another */
  786. X     printf("endpage\n") ;
  787. X     start_page = TRUE;
  788. X     /* Verification for binary files */
  789. X     if (first_page && is_binaryfile(name))
  790. X        return;
  791. X     line = 0;
  792. X     if ((c = getchar()) == EOF)
  793. X        break;
  794. X      }
  795. X
  796. X      /* Start a new line? */
  797. X      if (start_line)
  798. X      {
  799. X     if (start_page)
  800. X     {     /* only if there is something to print! */
  801. X        skip_page();
  802. X        start_page = FALSE ;
  803. X     }
  804. X     if (numbering)
  805. X        printf("(%-5d ", ++line_number);
  806. X     else
  807. X        printf("( ");
  808. X     start_line = FALSE;
  809. X      }
  810. X
  811. X      /* Interpret each character */
  812. X      switch (c)
  813. X      {
  814. X      case '\b':
  815. X     if (!interpret)
  816. X        goto print;
  817. X     if (column)
  818. X        column--;
  819. X     putchar(c);
  820. X     break;
  821. X      case '\n':
  822. X     column = 0;
  823. X     start_line = TRUE;
  824. X     printf(") s\n");
  825. X     if (++line >= linesperpage)
  826. X     {
  827. X        printf("endpage\n");
  828. X        start_page = TRUE ;
  829. X        if (first_page && is_binaryfile(name))
  830. X           return;
  831. X        line = 0;
  832. X     }
  833. X     break;
  834. X      case '\t':
  835. X     if (interpret)
  836. X     {
  837. X        continue_exit = FALSE;
  838. X        do
  839. X        {
  840. X           if (++column + prefix_width > columnsperline)
  841. X          if (folding)
  842. X          {
  843. X             if (fold_line(name) == FALSE)
  844. X            return;
  845. X          }
  846. X          else
  847. X          {
  848. X             c = cut_line();
  849. X             continue_exit = TRUE;
  850. X             break;
  851. X          }
  852. X           putchar(' ');
  853. X        } while (column % column_width);
  854. X        if (continue_exit)
  855. X           continue;
  856. X        break;
  857. X        }
  858. X      default:
  859. X      print:
  860. X     if (only_printable)
  861. X        char_width = 1;
  862. X     else
  863. X     {
  864. X        char_width = c > 0177 ? 2 : 0;
  865. X        char_width += c < ' ' || c == 0177 ? 2 : 1;
  866. X     }
  867. X     if (prefix_width + (column += char_width) > columnsperline)
  868. X        if (folding)
  869. X        {
  870. X           if (fold_line(name) == FALSE)
  871. X          return;
  872. X        }
  873. X        else
  874. X        {
  875. X           c = cut_line();
  876. X           continue;
  877. X        }
  878. X     nonprinting_chars += printchar(c);
  879. X     chars++;
  880. X     break;
  881. X      }
  882. X      c = getchar();
  883. X   }
  884. X
  885. X   if (!start_line)
  886. X      printf(") s\n");
  887. X   if (!start_page)
  888. X      printf("endpage\n");
  889. X}
  890. X
  891. X/*
  892. X * Cut long filenames.
  893. X */
  894. Xint cut_filename(old_name, new_name)
  895. Xchar *old_name, *new_name;
  896. X{
  897. X   register char *p;
  898. X   register int i;
  899. X
  900. X   p = old_name + (strlen(old_name)-1);
  901. X   while (p >= old_name && *p != DIR_SEP) p--;
  902. X
  903. X   for (i = 0, p++; *p != NULL && i < MAXFILENAME; i++)
  904. X      *new_name++ = *p++;
  905. X   *new_name = NULL;
  906. X}
  907. X
  908. X/*
  909. X * Fold a line too long.
  910. X */
  911. Xint fold_line(name)
  912. Xchar *name;
  913. X{
  914. X   column = 0;
  915. X   printf(") s\n");
  916. X   if (++line >= linesperpage)
  917. X   {
  918. X      printf("endpage\n");
  919. X      skip_page();
  920. X      if (first_page && is_binaryfile(name))
  921. X     return FALSE;
  922. X      line = 0;
  923. X   }
  924. X   if (numbering)
  925. X      printf("(      ");
  926. X   else
  927. X      printf("( ");
  928. X
  929. X   return TRUE;
  930. X}
  931. X
  932. X/*
  933. X * Cut a textline too long to the size of a page line.
  934. X */
  935. Xchar cut_line()
  936. X{
  937. X   char c;
  938. X
  939. X   while ((c = getchar()) != EOF && c != '\n' && c != '\f');
  940. X   return c;
  941. X}
  942. X
  943. X/*
  944. X * Print a char in a form accept by postscript printers.
  945. X */
  946. Xint printchar(c)
  947. Xunsigned char c;
  948. X{
  949. X   if (c >= ' ' && c < 0177)
  950. X   {
  951. X      if (c == '(' || c == ')' || c == '\\')
  952. X         putchar('\\');
  953. X      putchar(c);
  954. X      return 0;
  955. X   }
  956. X
  957. X   if (only_printable)
  958. X   {
  959. X      putchar(' ');
  960. X      return 1;
  961. X   }
  962. X
  963. X   if (c > 0177)
  964. X   {
  965. X      printf("M-");
  966. X      c &= 0177;
  967. X   }
  968. X   if (c < ' ')
  969. X   {
  970. X      putchar('^');
  971. X      if ((c = c + '@') == '(' || c == ')' || c == '\\')
  972. X     putchar('\\');
  973. X      putchar(c);
  974. X   }
  975. X   else if (c == 0177)
  976. X      printf("^?");
  977. X   else
  978. X      putchar(c);
  979. X
  980. X   return 1;
  981. X}
  982. X
  983. X/*
  984. X * Begins a new physical page.
  985. X */
  986. Xvoid skip_page()
  987. X{
  988. X   pages++;
  989. X   if (twinpage == FALSE || (pages & 0x1))
  990. X   {
  991. X      sheets++;
  992. X      printf("%%%%Page: %d %d\n", sheets, sheets);
  993. X   }
  994. X   printf("startpage\n");
  995. X}
  996. X
  997. X/*
  998. X * Test if we have a binary file.
  999. X */
  1000. Xis_binaryfile(name)
  1001. Xchar *name;
  1002. X{
  1003. X   first_page = FALSE;
  1004. X   if (!print_binaries && (nonprinting_chars*100 / chars) >= 75)
  1005. X   {
  1006. X      fprintf(stderr, "%s is a binary file: printing aborted\n", name);
  1007. X      return TRUE;
  1008. X   }
  1009. X   return FALSE;
  1010. X}
  1011. X
  1012. Xprint_header()
  1013. X{
  1014. X   register int c;
  1015. X   FILE *f;
  1016. X   char *string;
  1017. X#ifdef ANSIC
  1018. X   time_t date;
  1019. X#else
  1020. X#ifdef BSD
  1021. X   struct timeval date;
  1022. X   struct tm *p;
  1023. X#else
  1024. X#ifdef SYSV
  1025. X    struct timeb date;
  1026. X#endif
  1027. X#endif
  1028. X#endif
  1029. X
  1030. X   if ((f = fopen(HEADER_PS, "r")) == NULL)
  1031. X   {
  1032. X      fprintf(stderr, "Poscript header missing\n");
  1033. X      exit(1);
  1034. X   }
  1035. X
  1036. X   /* Initialize some postcript variables */
  1037. X   printf("%%! a2ps 3.0\n\n");
  1038. X   printf("/$a2psdict 100 dict def\n");
  1039. X   printf("$a2psdict begin\n");
  1040. X   printf("%% Initialize page description variables.\n");
  1041. X   printf("/inch {72 mul} bind def\n");
  1042. X   printf("/landscape %s def\n", landscape ? "true" : "false");
  1043. X   printf("/twinpage %s def\n", twinpage ? "true" : "false");
  1044. X   printf("/sheetheight %g inch def\n", HEIGHT);
  1045. X   printf("/sheetwidth %g inch def\n", WIDTH);
  1046. X   printf("/margin %g inch def\n", MARGIN);
  1047. X   printf("/noborder %s def\n", no_border ? "true" : "false");
  1048. X   if (no_header) {
  1049. X      printf("/noheader true def\n");
  1050. X      printf("/headersize 0.0 def\n");
  1051. X   }
  1052. X   else {
  1053. X      printf("/noheader false def\n");
  1054. X      printf("/headersize %g inch def\n",
  1055. X         landscape ? LANDSCAPE_HEADER : PORTRAIT_HEADER);
  1056. X   }
  1057. X   printf("/bodyfontsize %g def\n", font_size);
  1058. X   printf("/lines %d def\n", linesperpage);
  1059. X   printf("/columns %d def\n", columnsperline);
  1060. X
  1061. X   /* Retrieve date and hour */
  1062. X#ifdef ANSIC
  1063. X   if (time(&date) == -1)
  1064. X   {
  1065. X      fprintf(stderr, "Error calculing time\n");
  1066. X      exit(1);
  1067. X   }
  1068. X   string = ctime(&date);
  1069. X
  1070. X   /* and print them */
  1071. X   printf("/date (%.6s %.4s %.8s) def\n", string+4, string+20, string+11);
  1072. X#else
  1073. X#ifdef BSD
  1074. X   (void) gettimeofday(&date, (struct timezone *)0);
  1075. X   p = localtime(&date.tv_sec);
  1076. X   string = asctime(p);
  1077. X
  1078. X   /* and print them */
  1079. X   printf("/date (%.6s %.4s %.8s) def\n", string+4, string+20, string+11);
  1080. X#else
  1081. X#ifdef SYSV
  1082. X   (void)ftime(&date);
  1083. X   string = ctime(&date.time);
  1084. X   printf("/date (%.6s %.4s %.8s) def\n", string+4, string+20, string+11);
  1085. X#endif
  1086. X#endif
  1087. X#endif
  1088. X
  1089. X   /* Header file printing */
  1090. X   while ((c = getc(f)) != EOF)
  1091. X      putchar(c);
  1092. X
  1093. X
  1094. X   /* Close prolog */
  1095. X   printf("%%%%EndProlog\n\n");
  1096. X
  1097. X   /* Ask for printing n copies */
  1098. X   if (copies_number > 1)
  1099. X      printf("/#copies %d def\n", copies_number);
  1100. X
  1101. X   /* Go on */
  1102. X   printf("/docsave save def\n");
  1103. X   printf("startdoc\n");
  1104. X}
  1105. END_OF_FILE
  1106. if test 18394 -ne `wc -c <'a2ps.c'`; then
  1107.     echo shar: \"'a2ps.c'\" unpacked with wrong size!
  1108. fi
  1109. # end of 'a2ps.c'
  1110. fi
  1111. if test -f 'header.ps' -a "${1}" != "-c" ; then 
  1112.   echo shar: Will not clobber existing file \"'header.ps'\"
  1113. else
  1114. echo shar: Extracting \"'header.ps'\" \(8096 characters\)
  1115. sed "s/^X//" >'header.ps' <<'END_OF_FILE'
  1116. X%!  PostScript Source Code
  1117. X%
  1118. X%  File: imag:/users/local/a2ps/header.ps
  1119. X%  Created: Tue Nov 29 12:14:02 1988 by miguel@imag (Miguel Santana)
  1120. X%  Version: 2.0
  1121. X%  Description: PostScript prolog for a2ps ascii to PostScript program.
  1122. X% 
  1123. X%  Edit History:
  1124. X%  - Original version by evan@csli (Evan Kirshenbaum).
  1125. X%  - Modified by miguel@imag to:
  1126. X%    1) Correct an overflow bug when printing page number 10 (operator
  1127. X%    cvs).
  1128. X%    2) Define two other variables (sheetwidth, sheetheight) describing
  1129. X%    the physical page (by default A4 format).
  1130. X%    3) Minor changes (reorganization, comments, etc).
  1131. X%  - Modified by tullemans@apolloway.prl.philips.nl
  1132. X%    1) Correct stack overflows with regard to operators cvs and copy.
  1133. X%       The resulting substrings where in some cases not popped off 
  1134. X%       the stack, what can result in a stack overflow.
  1135. X%    2) Replaced copypage and erasepage by showpage. Page througput
  1136. X%       degrades severely (see red book page 140) on our ps-printer
  1137. X%       after printing sheet 16 (i.e. page 8) of a file which was 
  1138. X%       actually bigger. For this purpose the definitions of startdoc
  1139. X%       and startpage are changed.
  1140. X%  - Modified by Tim Clark <T.Clark@uk.ac.warwick> to:
  1141. X%    1) Print one page per sheet (portrait) as an option.
  1142. X%    2) Reduce size of file name heading, if it's too big.
  1143. X%    3) Save and restore PostScript state at begining/end. It now uses
  1144. X%    conventional %%Page %%Trailer markers.
  1145. X%    4) Print one wide page per sheet in landscape mode as an option.
  1146. X%  - Modified by miguel@imag.fr to
  1147. X%    1) Add new option to print n copies of a file.
  1148. X%    2) Add new option to suppress heading printing.
  1149. X%    3) Add new option to suppress page surrounding border printing.
  1150. X%    4) Add new option to change font size. Number of lines and columns
  1151. X%    are now automatically adjusted, depending on font size and
  1152. X%    printing mode used.
  1153. X%    5) Minor changes (best layout, usage message, etc).
  1154. X%
  1155. X
  1156. X% Copyright (c) 1988, Miguel Santana, miguel@imag.imag.fr
  1157. X%
  1158. X% Permission is granted to copy and distribute this file in modified
  1159. X% or unmodified form, for noncommercial use, provided (a) this copyright
  1160. X% notice is preserved, (b) no attempt is made to restrict redistribution
  1161. X% of this file, and (c) this file is not distributed as part of any
  1162. X% collection whose redistribution is restricted by a compilation copyright.
  1163. X%
  1164. X
  1165. X
  1166. X% General macros.
  1167. X/xdef {exch def} bind def
  1168. X/getfont {exch findfont exch scalefont} bind def
  1169. X
  1170. X% Page description variables and inch function are defined by a2ps program.
  1171. X
  1172. X% Character size for differents fonts.
  1173. X   landscape
  1174. X   { /filenamefontsize 12 def }
  1175. X   { /filenamefontsize 16 def }
  1176. Xifelse
  1177. X/datefontsize filenamefontsize 0.8 mul def
  1178. X/headermargin filenamefontsize 0.25 mul def
  1179. X/bodymargin bodyfontsize 0.7 mul def
  1180. X
  1181. X% Font assignment to differents kinds of "objects"
  1182. X/filenamefontname /Helvetica-Bold def
  1183. X/stdfilenamefont filenamefontname filenamefontsize getfont def
  1184. X/datefont /Helvetica datefontsize getfont def
  1185. X/bodyfont /Courier bodyfontsize getfont def
  1186. X
  1187. X% Logical page attributs (a half of a real page or sheet).
  1188. X/pagewidth
  1189. X   bodyfont setfont (0) stringwidth pop columns mul bodymargin dup add add
  1190. X   def
  1191. X/pageheight
  1192. X   bodyfontsize lines mul bodymargin dup add add headersize add
  1193. X   def
  1194. X
  1195. X% Coordinates for upper corner of a logical page and for sheet number.
  1196. X% Coordinates depend on format mode used.
  1197. X% In twinpage mode, coordinate x of upper corner is not the same for left
  1198. X% and right pages: upperx is an array of two elements, indexed by sheetside.
  1199. X/rightmargin margin 3 div def
  1200. X/leftmargin margin 2 mul 3 div def
  1201. X/topmargin margin twinpage {3} {2} ifelse div def
  1202. Xlandscape
  1203. X{  % Landscape format
  1204. X   /uppery rightmargin pageheight add bodymargin add def
  1205. X   /sheetnumbery sheetwidth leftmargin pageheight add datefontsize add sub def
  1206. X   twinpage
  1207. X   {  % Two logical pages
  1208. X      /upperx [ topmargin            % upperx for left page
  1209. X        dup 2 mul pagewidth add        % upperx for right page
  1210. X          ] def
  1211. X      /sheetnumberx sheetheight topmargin sub def
  1212. X   }
  1213. X   {  /upperx [ topmargin dup ] def
  1214. X      /sheetnumberx sheetheight topmargin sub datefontsize sub def
  1215. X   }
  1216. X   ifelse
  1217. X}
  1218. X{  % Portrait format
  1219. X   /uppery topmargin pageheight add def
  1220. X   /upperx [ leftmargin dup ] def
  1221. X   /sheetnumberx sheetwidth rightmargin sub datefontsize sub def
  1222. X   /sheetnumbery
  1223. X     sheetheight 
  1224. X     topmargin pageheight add datefontsize add headermargin add
  1225. X      sub
  1226. X      def
  1227. X
  1228. X}
  1229. Xifelse
  1230. X
  1231. X% Strings used to make easy printing numbers
  1232. X/pnum 12 string def
  1233. X/empty 12 string def
  1234. X
  1235. X% Other initializations.
  1236. X/datewidth date stringwidth pop def
  1237. X/filenameroom
  1238. X         pagewidth
  1239. X     filenamefontsize 4 mul datewidth add (Page 999) stringwidth pop add
  1240. X      sub
  1241. X   def
  1242. X
  1243. X
  1244. X% Function startdoc: initializes printer and global variables.
  1245. X/startdoc
  1246. X    { /sheetside 0 def            % sheet side that contains current page
  1247. X      /sheet 1 def            % sheet number
  1248. X   } bind def
  1249. X
  1250. X% Function newfile: init file name and reset page number for each new file.
  1251. X/newfile
  1252. X    { cleanup
  1253. X      /filename xdef
  1254. X      /filenamewidth filename stringwidth pop def
  1255. X      /filenamefont
  1256. X     filenamewidth filenameroom gt
  1257. X     {
  1258. X           filenamefontname
  1259. X           filenamefontsize filenameroom mul filenamewidth div
  1260. X        getfont
  1261. X     }
  1262. X     {  stdfilenamefont }
  1263. X     ifelse
  1264. X     def
  1265. X      /pagenum 1 def
  1266. X    } bind def
  1267. X
  1268. X% Function printpage: Print a physical page.
  1269. X/printpage
  1270. X    { /sheetside 0 def
  1271. X      twinpage
  1272. X      {  noborder not
  1273. X        { sheetnumber }
  1274. X     if
  1275. X      }
  1276. X      {  noheader noborder not and
  1277. X        { sheetnumber }
  1278. X     if
  1279. X      }
  1280. X      ifelse
  1281. X      showpage 
  1282. X%      pagesave restore
  1283. X      /sheet sheet 1 add def
  1284. X    } bind def
  1285. X
  1286. X% Function cleanup: terminates printing, flushing last page if necessary.
  1287. X/cleanup
  1288. X    { twinpage sheetside 1 eq and
  1289. X         { printpage }
  1290. X      if
  1291. X    } bind def
  1292. X
  1293. X%
  1294. X% Function startpage: prints page header and page border and initializes
  1295. X% printing of the file lines.
  1296. X/startpage
  1297. X    { sheetside 0 eq
  1298. X    { % /pagesave save def
  1299. X      landscape
  1300. X        { sheetwidth 0 inch translate    % new coordinates system origin
  1301. X          90 rotate                % landscape format
  1302. X        } if
  1303. X    } if
  1304. X      noborder not { printborder } if
  1305. X      noheader not { printheader } if
  1306. X     upperx sheetside get  bodymargin  add
  1307. X        uppery
  1308. X        bodymargin bodyfontsize add  noheader {0} {headersize} ifelse  add
  1309. X     sub
  1310. X      moveto
  1311. X      bodyfont setfont
  1312. X    } bind def
  1313. X
  1314. X% Function printheader: prints page header.
  1315. X/printheader
  1316. X    { upperx sheetside get  uppery headersize sub 1 add  moveto
  1317. X      datefont setfont
  1318. X      gsave
  1319. X        datefontsize headermargin rmoveto
  1320. X    date show                    % date/hour
  1321. X      grestore
  1322. X      gsave
  1323. X    pagenum pnum cvs pop
  1324. X       pagewidth (Page 999) stringwidth pop sub
  1325. X       headermargin
  1326. X    rmoveto
  1327. X        (Page ) show pnum show                % page number
  1328. X      grestore
  1329. X      empty pnum copy pop
  1330. X      gsave
  1331. X        filenamefont setfont
  1332. X          filenameroom filename stringwidth pop sub 2 div datewidth add
  1333. X          bodymargin 2 mul 
  1334. X       add 
  1335. X       headermargin
  1336. X    rmoveto
  1337. X        filename show                        % file name
  1338. X      grestore
  1339. X    } bind def
  1340. X
  1341. X% Function printborder: prints border page.
  1342. X/printborder 
  1343. X    { upperx sheetside get uppery moveto
  1344. X      gsave                    % print the four sides
  1345. X        pagewidth 0 rlineto            % of the square
  1346. X        0 pageheight neg rlineto
  1347. X        pagewidth neg 0 rlineto
  1348. X        closepath stroke
  1349. X      grestore
  1350. X      noheader not
  1351. X         { 0 headersize neg rmoveto pagewidth 0 rlineto stroke }
  1352. X      if
  1353. X    } bind def
  1354. X
  1355. X%
  1356. X% Function endpage: adds a sheet number to the page (footnote) and prints
  1357. X% the formatted page (physical impression). Activated at the end of each
  1358. X% source page (lines reached or FF character).
  1359. X/endpage
  1360. X   { /pagenum pagenum 1 add def
  1361. X     twinpage  sheetside 0 eq  and
  1362. X        { /sheetside 1 def }
  1363. X        { printpage }
  1364. X     ifelse
  1365. X   } bind def
  1366. X
  1367. X% Function sheetnumber: prints the sheet number.
  1368. X/sheetnumber
  1369. X    { sheetnumberx sheetnumbery moveto
  1370. X      datefont setfont
  1371. X      sheet pnum cvs
  1372. X     dup stringwidth pop (0) stringwidth pop sub neg 0 rmoveto show
  1373. X      empty pnum copy pop
  1374. X    } bind def
  1375. X
  1376. X% Function s: print a source line
  1377. X/s  { gsave
  1378. X        show
  1379. X      grestore
  1380. X      0 bodyfontsize neg rmoveto
  1381. X    } bind def
  1382. END_OF_FILE
  1383. if test 8096 -ne `wc -c <'header.ps'`; then
  1384.     echo shar: \"'header.ps'\" unpacked with wrong size!
  1385. fi
  1386. # end of 'header.ps'
  1387. fi
  1388. echo shar: End of shell archive.
  1389. exit 0
  1390. -- 
  1391. Miguel SANTANA   miguel@imag.fr or miguel@imag.UUCP (uunet.uu.net!imag!miguel)
  1392.  
  1393.